package com.base.controller;

import com.base.comm.CommContent;
import com.base.po.voip.Classify;
import com.base.service.ClassifyService;
import com.base.service.LogsService;
import com.base.utils.IP;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;

/**
 * 添加分类信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class add_Classify {

	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private ClassifyService classifyService; // 分类信息

	// 添加分类
	@RequestMapping(value = "/toAddClassify", method = RequestMethod.POST)
	public @ResponseBody int toAddClassify(HttpServletRequest request, @RequestBody Classify classify)
			throws Exception {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录
        classify.setId(Produce.getUUID()); // 设置参数 UUID
        classify.setCreatetime(Produce.getNowDate()); // 创建时间
        classify.setAgentid(userid); // 代理商ID
        classify.setDatastatus((byte) 1); // 状态可用
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置分类信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return classifyService.insertSelective(classify); // 添加
	}
}
